package com.interpreter.interpreter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Test {
    public static void main(String[] args) throws IOException {
        String expStr = getExpStr();
        HashMap<String, Integer> paramValue =setValue(expStr);
        System.out.println(paramValue);
        Calculator calculator = new Calculator(expStr);
        System.out.println("运算结果："+calculator.run(paramValue));
    }

    //获取表达式
    public static String getExpStr(){
        String exp = "";
        System.out.println("请输入表达式，仅仅包含  + - 和int值");
        try {
            exp = (new BufferedReader(new InputStreamReader(System.in))).readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return exp ;
    }

    //获取映射值
    public static HashMap<String ,Integer>setValue(String expStr) throws IOException {
        HashMap<String ,Integer> map = new HashMap<>();

        for (char c : expStr.toCharArray()) {
            if (c != '+' && c != '-'){
                System.out.println("请输入【"+c+"】的值:");
                String s =new BufferedReader(new InputStreamReader(System.in)).readLine();
                int i = Integer.parseInt(s);
                map.put(String.valueOf(c) , i);
            }
        }

        return map  ;
    }

}
